import {ecs} from "db://oops-framework/libs/ecs/ECS";
import {ChuPaiComp} from "db://assets/script/game/majiang/comp/chuPaiComp";
import {api, pt} from "db://assets/script/game/player/api";
import {smc} from "db://assets/script/game/common/singletonModuleComp";
import {Player} from "db://assets/script/game/player/player";

// 操作麻将
export class OpChooseSystem extends ecs.ComblockSystem implements ecs.IEntityEnterSystem {
    filter(): ecs.IMatcher {
        return ecs.anyOf(ChuPaiComp)
    }

    entityEnter(entity: ecs.Entity) {
        let comp: any
        if (entity.has(ChuPaiComp)) {
            comp = entity.get(ChuPaiComp)
            const tid = comp.tid
            const tileIndex = comp.tileIndex
            entity.remove(comp)
            api.mjOpChoose({
                type: pt.MjOpTpe.chu,
                tileIndex: tileIndex,
            }, () => {
                const playerView = smc.gameMj.getPlayerSideView(Player.shortId())
                playerView.dropCard(tid, tileIndex)
            })
        }
    }
}
